<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>韩城市综合行政执法局业务审批管理系统</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="__ADMIN__/bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="__ADMIN__/bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="__ADMIN__/bower_components/Ionicons/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="__ADMIN__/dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="__ADMIN__/dist/css/skins/_all-skins.min.css">
  <!-- Morris chart -->
  <link rel="stylesheet" href="__ADMIN__/bower_components/morris.js/morris.css">
  <!-- jvectormap -->
  <link rel="stylesheet" href="__ADMIN__/bower_components/jvectormap/jquery-jvectormap.css">
  <!-- Date Picker -->
  <link rel="stylesheet" href="__ADMIN__/bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
  <!-- Daterange picker -->
  <link rel="stylesheet" href="__ADMIN__/bower_components/bootstrap-daterangepicker/daterangepicker.css">
  <!-- bootstrap wysihtml5 - text editor -->
  <link rel="stylesheet" href="__ADMIN__/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
  <!-- 自定义样式 -->
  <link rel="stylesheet" href="__ADMIN__/css/style.css">
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
  <!-- jQuery 3 -->
  <script src="__ADMIN__/bower_components/jquery/dist/jquery.min.js"></script>
  <script src="__PLUS__/layer/layer.js"></script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <!-- 头部 -->
  {include file="common/header"}
  <!-- //头部 -->

  <!-- 左侧导航 -->
  {include file="common/left"}
  <!-- /左侧导航 -->

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        管理员管理

      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 系统</a></li>
        <li class="active">系统设置</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">管理员列表</h3>

              <div class="box-tools">
                <div class="input-group input-group-sm" style="width: 150px;">
                  <a class="add btn bg-olive margin"  href = 'javascript:;' >添加管理员</a>

                  <div class="input-group-btn">

                  </div>
                </div>
              </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding ">
              <table class="table table-hover text-center">
                <tr>
                  <th>ID</th>
                  <th>姓名</th>
                  <th>部门</th>
                  <th>用户组</th>
                  <th>状态</th>
                  <th>操作</th>
                </tr>
                {volist name="list" id="vo"}
                <tr>
                  <td>{$vo.id}</td>
                  <td>{$vo.name}</td>
                  <td>{$vo.position.pname}</td>
                  <td>{$vo.groupTitle}</td>

                  <td><a  userid="{$vo.id}" onClick="changestatus(this);" {if condition="$vo['status'] eq 1"}class="label label-success"{else}class="label label-danger"{/if} href="javascript:">{if condition="$vo['status'] eq 1"}启用{else}禁用{/if}</span></td>



                  <td><div>
                    <a class="edit" style="margin-right: 20px;" data-eid="{$vo['id']}" data-id="{:url('admin/edit',array('id'=>$vo['id']))}" href="javascript:;">
                      <i class="fa fa-pencil"></i>
                    </a>
                    <a class="del" data-id="{:url('admin/del',array('id'=>$vo['id']))}" href="javascript:;">
                      <i class="fa fa-trash-o"></i>
                    </a>
                  </div></td>
                </tr>
                {/volist}
              </table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
      </div>

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <!-- 底部 -->
  {include file="common/footer"}
  <!-- /底部 -->
 <div id="editbox"  style="display:none;">

   <div class="box-body form-horizontal">
     <div class="form-group">
       <label class="col-sm-3 control-label">姓名</label>
       <div class="col-sm-9">
         <input  class="form-control" name="name" value="" >
       </div>
     </div>
     <div class="form-group">
       <label class="col-sm-3 control-label">密码</label>
       <div class="col-sm-9">
         <input type="password" class="form-control" id="epassword" name="password" >
       </div>
     </div>
     <div class="form-group">
       <label class="col-sm-3 control-label">部门</label>
       <div class="col-sm-9">
         <select class="form-control" name="eposition" id="eposition">

           {volist name="position" id="vo"}
           <option id="room{$vo.id}" value="{$vo.id}">{$vo.pname}</option>
           {/volist}
         </select>
       </div>
     </div>
     <div class="form-group">
       <label class="col-sm-3 control-label">用户组</label>

       <div class="col-sm-9">
         <select class="form-control" name="group_id" id="egroup">
           <option value="">请选择</option>
           {volist name="authGroupRes" id="vo"}
             <option id="group{$vo.id}" value="{$vo.id}">{$vo.title}</option>
           {/volist}
         </select>
       </div>
     </div>

     <div class="box-footer text-center">

       <button type="button" data-id="" id="edituser" class="btn btn-default edituser">提交</button>

     </div>




   </div>
 </div>

  <div id="addbox" style="display:none;">
    <div class="box-body form-horizontal">
      <div class="form-group">
        <label class="col-sm-3 control-label">姓名</label>

        <div class="col-sm-9">
          <input  class="form-control" name="name" id="name" >
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label">密码</label>

        <div class="col-sm-9">
          <input type="password" class="form-control" id="password" name="password" >
        </div>
      </div>

      <div class="form-group">
        <label class="col-sm-3 control-label">部门</label>

        <div class="col-sm-9">
          <select class="form-control" name="position" id="position_id">
            <option value="">请选择</option>
            {volist name="position" id="vo"}
            <option value="{$vo.id}">{$vo.pname}</option>
            {/volist}
          </select>
        </div>
      </div>

      <div class="form-group">
        <label class="col-sm-3 control-label">用户组</label>

        <div class="col-sm-9">
          <select class="form-control" name="group_id" id="group_id">
            <option value="">请选择</option>
            {volist name="authGroupRes" id="vo"}
            <option value="{$vo.id}">{$vo.title}</option>
            {/volist}
          </select>
        </div>
      </div>


    </div>
    <!-- /.box-body -->
    <div class="box-footer text-center">

      <button type="submit" class="btn btn-info adduser" id="adduser">提交</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <button type="reset" class="btn btn-default ">取消</button>

    </div>
    <!-- /.box-footer -->
  </form>

</div>
<!-- ./wrapper -->
<script>

  function layer_msg(msg,icon,time){
      layer.msg(msg, {
          icon: icon,
          time: time,
          end: function () {
              location.reload();
          }
      });
  }
    $('.del').on('click', function(){
        var urld = $(this).attr('data-id');
        //询问框
        layer.confirm('确定要删除吗？', {
            btn: ['确认','取消'], //按钮
            title: '系统警告！'
        }, function(){
            console.log(urld);
            location.href=urld;
        });
    });

    $('.edit').on('click', function(){

        $.ajax({
            url: "{:url('admin/ajaxEdit')}",
            type: 'POST',
            dataType: 'json',
            data: {
                eid:$(this).attr('data-eid')
            }
        })
        .done(function(res) {

            if(res.ECODE == 200){
                console.log(res);
                $('#editbox').find('input[name=name]').val(res.MSG.name);
                $('#editbox').find('input[name=epassword]').val(res.MSG.password);
                $('#edituser').attr('data-id',res.MSG.id);
                $('#room'+res.MSG.position_id).attr('selected',true);
                $('#group'+res.MSG.group_id).attr('selected',true);



                        //页面层
                layer.open({
                    type: 1,
                    title: '修改管理员',
                    skin: 'layui-layer-rim', //加上边框
                    area: ['480px', '340px'], //宽高
                    content: $('#editbox')
                });
            }
        });
    });

    $('.edituser').on('click', function () {
        $.ajax({
            url: "{:url('admin/ajaxseave')}",
            type: 'POST',
            dataType: 'json',
            data: {
                name:$('#editbox').find('input[name=name]').val(),
                id:$(this).attr('data-id'),
                password:$('#epassword').val(),
                position_id:$('#eposition option:selected') .val(),
                group_id:$('#egroup option:selected') .val()
            }
        })
            .done(function(res) {
                console.log(res)
                if(res.ECODE == 200){
                    layer_msg("修改成功",1,1000);

                }
            });
    });

    $('.add').on('click', function() {
        layer.open({
            type: 1,
            title: '添加管理员',
            skin: 'layui-layer-rim', //加上边框
            area: ['480px', '320px'], //宽高
            content: $('#addbox')
        });

    $('.adduser').on('click', function () {
        $.ajax({
            url: "{:url('admin/ajaxadd')}",
            type: 'POST',
            dataType: 'json',
            data: {
                name:$('#name').val(),
                password:$('#password').val(),
                position_id:$('#position_id option:selected').val(),
                group_id:$('#group_id option:selected').val()
            }
        })
            .done(function(res) {
                //console.log(res)
                if(res.ECODE == 200){

                    layer_msg("添加管理员成功",1,1000);
                }
            });
    });




    } );


  //ajax异步修改管理员状态
  function changestatus(o){
      var userid=$(o).attr("userid");
      $.ajax({
          type:"post",
          dataType:"json",
          data:{userid:userid},
          url:"{:url('admin/changestatus')}",
          success:function(data){
              if(data==1){
                  $(o).attr("class","label label-danger");
                  $(o).text('禁用');
              }
              else{
                  $(o).attr("class","label label-success");
                  $(o).text('启用');
              }
          }
      });
  }







</script>

<!-- Bootstrap 3.3.7 -->
<script src="__ADMIN__/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Morris.js charts -->
<script src="__ADMIN__/bower_components/raphael/raphael.min.js"></script>
<script src="__ADMIN__/bower_components/morris.js/morris.min.js"></script>
<!-- Sparkline -->
<script src="__ADMIN__/bower_components/jquery-sparkline/dist/jquery.sparkline.min.js"></script>
<!-- jvectormap -->
<script src="__ADMIN__/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="__ADMIN__/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<!-- jQuery Knob Chart -->
<script src="__ADMIN__/bower_components/jquery-knob/dist/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="__ADMIN__/bower_components/moment/min/moment.min.js"></script>
<script src="__ADMIN__/bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
<!-- datepicker -->
<script src="__ADMIN__/bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<!-- Bootstrap WYSIHTML5 -->
<script src="__ADMIN__/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<!-- Slimscroll -->
<script src="__ADMIN__/bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="__ADMIN__/bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="__ADMIN__/dist/js/adminlte.min.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="__ADMIN__/dist/js/pages/dashboard.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="__ADMIN__/dist/js/demo.js"></script>
</body>
</html>
